﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Enlightener.Engine.Utils
{
    internal enum InternalVersion
    {
        V1_7,
        V1_8,
        V1_9
    }

    public struct ConfuserSignature
    {
        internal InternalVersion @InternalVersion { get; set; }
        public string Version { get; set; }
    }

    public static class Identifier
    {
        public static ConfuserSignature FindSignature()
        {
            var pattern = new Regex("Confuser v[0-9].[0-9].[0-9].[0-9]");
            var match = pattern.Match(File.ReadAllText(DeobfuscatorContext.InPath));

            if(match.Captures.Count == 0)
            {
                Logger.ELog("Could not detect confuser signature!");
                Console.ReadLine();
                Environment.Exit(-1);
            }

            var eVer = "";
            Logger.VSLog("Detected: " + (eVer = match.Groups[0].Value));

            var iVer = InternalVersion.V1_7;

            if(eVer.Contains("1.8"))
                iVer = InternalVersion.V1_8;
            else if (eVer.Contains("1.9"))
                iVer = InternalVersion.V1_9;

            return new ConfuserSignature
                       {
                           Version = eVer,
                           InternalVersion = iVer
                       };
        }
    }
}
